package com.ryan.spring.annotation.config;

import com.ryan.spring.annotation.model.Car;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;

/**
 * Created by kaimin on 28/1/2019.
 * time : 13:14
 */
@Component
public class CarBeanPostProcessor implements BeanPostProcessor{

    @Nullable
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof Car) {
            System.out.println("BeanPostProcessor的Before:"+beanName);
        }

        return bean;
    }

    @Nullable
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof Car) {
            System.out.println("BeanPostProcessor的After:"+beanName);
        }
        return bean;
    }
}
